<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.soeasy.util.UserUtil"%>
<%@page import="com.feib.soeasy.action.Soez9008ActionBean"%>
<%@page import="com.feib.soeasy.model.UserActionLog"%>

<%
	Soez9008ActionBean actionBean =(Soez9008ActionBean) request.getAttribute("actionBean");
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title><%=UserUtil.getCurrentMenuItemName() %></title>
	<script type="text/javascript" src="<c:url value='/scripts/jquery/jquery.bgiframe-2.1.2.js'/>"></script>
	
	<script type="text/javascript">
	<!--	
	$(document).ready(function() {
		

		
		$('#findGroupNoImg').click(function() {
		var groupNo = $('#qryFormatDefinition\\.group\\.groupNo').val();
		
		if (null != groupNo && 0 != groupNo.length){
			var tmpGroupNo = parseInt(groupNo,10);
			if(! isNaN(tmpGroupNo)){
				$('#hidden\\.queryGroupTrigger').val('');
				$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
				$('#hidden\\.qryGroup\\.groupName').val('');
				$('#qryGroup\\.groupNo').val(groupNo);
				$('#qryGroup\\.groupName').val('');
			}
			else{
				$('#hidden\\.queryGroupTrigger').val('');
				$('#hidden\\.qryGroup\\.groupNo').val('');
				$('#hidden\\.qryGroup\\.groupName').val(groupNo);
				$('#qryGroup\\.groupNo').val('');
				$('#qryGroup\\.groupName').val(groupNo);
				$("#queryGroupResultDiv").html('');
			}
			
			$("#findGroupDiv" ).dialog({  
				title:'帳單業者查詢' 
				, width: 600
				, resizable: true
				, modal: true
			});
			
			$('#doAjaxQueryGroupsBtn').click();
		}
		else{
			$('#hidden\\.queryGroupTrigger').val('');
			$('#hidden\\.qryGroup\\.groupNo').val('');
			$('#hidden\\.qryGroup\\.groupName').val('');
			$('#qryGroup\\.groupNo').val('');
			$('#qryGroup\\.groupName').val('');
			$("#queryGroupResultDiv").html('');
			$("#findGroupDiv" ).dialog({  
				title:'帳單業者查詢' 
				, width: 600
				, resizable: true
				, modal: true
			});
		}

		});

		$('#doAjaxQueryGroupsBtn').click(function() {
			var groupNo = $('#qryGroup\\.groupNo').val();
			var groupName = $('#qryGroup\\.groupName').val();
			$("#queryGroupResultDiv").html('');

			$('#hidden\\.qryGroup\\.groupNo').val(groupNo);
			$('#hidden\\.qryGroup\\.groupName').val(groupName);
			doQueryGroupAction(1);
			
		});
		
		$('#doAjaxCloseGroupsBtn').click(function() {
			$("#findGroupDiv" ).dialog( "destroy" );
		});
		
		
		
		

		$('#doQueryBtn').click(function() {
			var errMsg = "";
			var groupNo = $('#qryFormatDefinition\\.group\\.groupNo').val();
			if (null == groupNo || 0 == groupNo.length){
				errMsg = errMsg + "業者代號 是必要欄位<br/>";
			}//2011/06/16 jeff Gu  start   修正    業者代號不存在時 查詢錯誤問題
			else if (12 != groupNo.length){
				errMsg = errMsg + "業者代號 為固定長度12碼<br/>";
			}
			//2011/06/16 jeff Gu  end   修正    業者代號不存在時 查詢錯誤問題
		
			
			
			
			if (0 != errMsg.length){
				$("#ajaxErrorMessageDiv").html(errMsg);
				//$("#ajaxErrorMessageDiv" ).dialog( "destroy" );
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'請修正下列錯誤' 
					,width: 300
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				return false;
			}
			
			$('#hidden\\.qryFormatDefinition\\.group\\.groupNo').val(groupNo);
			doQueryAction(1);
		});
		
		$('#toAddBtn').click(function() {
			waitingDialog({});
			$.ajax({
				url : "<c:url value='/ajax/Soez9008.action'/>",
				async : true,
				type : 'POST',
				data : {toNewAjaxEditFomatDefinition: 'toNewAjaxEditFomatDefinition'},
				dataType : 'html',
				success : function(data, textStatus, XMLHttpRequest) {						
					$("#editFormatDefinitionDiv").html('');					
					$("#editFormatDefinitionDiv").html(data);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {
					$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
					$("#ajaxErrorMessageDiv").dialog({
						title : '系統錯誤',
						width : 600,
						resizable : false,
						modal : true,
						buttons : {
							Ok : function() {
								$(this).dialog("close");
							}
						}
					});
				},
				complete : function(XMLHttpRequest, textStatus) {
					closeWaitingDialog();
				}
			});
			
		});
		
		
		
		
	});


	function doQueryGroupAction(pageNumber)
	{
		$('#hidden\\.queryGroupResult\\.pageNumber').val(pageNumber);
		$("#queryGroupResultDiv").fadeTo("slow", 0.1);

		waitingDialog({});
		$.ajax({url : "<c:url value='/ajax/Soez9008.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryGroupHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest){
					$("#queryGroupResultDiv").html(data);
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'系統錯誤' 
					,width: 600
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				},
			complete: function(XMLHttpRequest, textStatus){
				if ($.browser.msie && /msie 6\.0/i.test(navigator.userAgent)){
					$("#findGroupDiv" ).dialog( "close" );
					$("#findGroupDiv" ).dialog( "open" );					
				}
				closeWaitingDialog();
				$("#queryGroupResultDiv").fadeTo("slow", 1);
			}
		});
	}

	function doSaveGroupApp()
	{
		var groupPk = $('#editGroup\\.groupPk').val();
		var chainstoreAmount = $('#editGroup\\.chainstoreAmount').val();
		var postAmount = $('#editGroup\\.postAmount').val();
		var atmAmount = $('#editGroup\\.atmAmount').val();
		var bankAmount = $('#editGroup\\.bankAmount').val();
		var remittanceAmount = $('#editGroup\\.remittanceAmount').val();
		var otherAmount = $('#editGroup\\.otherAmount').val();
		var selfAmount = $('#editGroup\\.selfAmount').val();

		$('#method').attr('name','toSaveAppGroup');
		
		$('#hidden\\.editGroup\\.groupPk').val(groupPk);
		$('#hidden\\.editGroup\\.chainstoreAmount').val(chainstoreAmount);
		$('#hidden\\.editGroup\\.postAmount').val(postAmount);
		$('#hidden\\.editGroup\\.bankAmount').val(bankAmount);
		$('#hidden\\.editGroup\\.atmAmount').val(atmAmount);
		$('#hidden\\.editGroup\\.remittanceAmount').val(remittanceAmount);
		$('#hidden\\.editGroup\\.otherAmount').val(otherAmount);
		$('#hidden\\.editGroup\\.selfAmount').val(selfAmount);
	        
		waitingDialog({});
		$.ajax({
			url : "<c:url value='/ajax/Soez9008.action'/>",
			async : true,
			type : 'POST',
			data : $("#saveAppGroupHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest) {					
				$("#saveAppGroupHiddenFormDiv").html(data);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv").dialog("destroy");
				$("#ajaxErrorMessageDiv").dialog({
					title : '系統錯誤',
					width : 600,
					resizable : false,
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
						}
					}
				});
			},
			complete : function(XMLHttpRequest, textStatus) {
				closeWaitingDialog();
				$("#saveAppGroupHiddenFormDiv").fadeTo("hide", 1);
			}
		});
	}
   
	function doSaveGroupAppPost()
	{
		var groupPk = $('#editGroup\\.groupPk').val();
		var postLevel1 = $('#editGroup\\.postLevel1').val();
		var postLevel2 = $('#editGroup\\.postLevel2').val();
		var postLevel3 = $('#editGroup\\.postLevel3').val();
		
		$('#method').attr('name','toSaveAppGroup');
		
		$('#hidden\\.editGroup\\.groupPk').val(groupPk);
		$('#hidden\\.editGroup\\.postLevel1').val(postLevel1);
		$('#hidden\\.editGroup\\.postLevel2').val(postLevel2);
		$('#hidden\\.editGroup\\.postLevel3').val(postLevel3);
		        
		waitingDialog({});
		$.ajax({
			url : "<c:url value='/ajax/Soez9008.action'/>",
			async : true,
			type : 'POST',
			data : $("#saveAppGroupHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest) {					
				$("#saveAppGroupHiddenFormDiv").html(data);
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv").dialog("destroy");
				$("#ajaxErrorMessageDiv").dialog({
					title : '系統錯誤',
					width : 600,
					resizable : false,
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
						}
					}
				});
			},
			complete : function(XMLHttpRequest, textStatus) {
				closeWaitingDialog();
				$("#saveAppGroupHiddenFormDiv").fadeTo("hide", 1);
			}
		});
	}

	
	function doQueryAction(pageNumber)
	{
		if (null != pageNumber)
			$('#hidden\\.queryResult\\.pageNumber').val(pageNumber);
		$("#queryResultDiv").fadeTo("slow", 0.1);

		waitingDialog({});
		$.ajax({url : "<c:url value='/ajax/Soez9008.action'/>",
			async : true,
			type : 'POST',
			data : $("#queryHiddenFrom").serialize(),
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest){
					$("#queryResultDiv").html(data);					
				},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv" ).dialog({  
					title:'系統錯誤' 
					,width: 600
					, resizable: false
					, modal: true
					, buttons: {
						Ok: function() {
							$( this ).dialog( "close" );
						}
					}
				});
				},
			complete: function(XMLHttpRequest, textStatus){
				closeWaitingDialog();
				$("#queryResultDiv").fadeTo("slow", 1);
			}
		});
	}
	
	function toAjaxEditRealAccountAction(groupPk)
	{
		waitingDialog({});
		$.ajax({
			url : "<c:url value='/ajax/Soez9007.action'/>",
			async : true,
			type : 'POST',
			data : {toAjaxEditRealAccount: 'toAjaxEditRealAccount', 'editGroup.groupPk': groupPk, 'queryRealAccount.pageSize': 100},
			dataType : 'html',
			success : function(data, textStatus, XMLHttpRequest) {
				$("#editRealAccountDiv").html(data);
				$("#editRealAccountDiv").dialog({
					title : '<%=UserUtil.getCurrentMenuItemName() %>',
					width : 600,
					resizable : false,
					modal : true
				});
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
				$("#ajaxErrorMessageDiv").html('系統發生錯誤，請聯絡管理員');
				$("#ajaxErrorMessageDiv").dialog({
					title : '系統錯誤',
					width : 600,
					resizable : false,
					modal : true,
					buttons : {
						Ok : function() {
							$(this).dialog("close");
						}
					}
				});
			},
			complete : function(XMLHttpRequest, textStatus) {
				closeWaitingDialog();
			}
		});
	}
	
	function doFormatTypeChange()
	{
		var formatTypeValue = $("#editFormatDefinition\\.formatType").val();
		
		if ('1' == formatTypeValue){
			$('#tr\\.editFormatDefinition\\.jrxmlPath').show();
			$('#tr\\.editFormatDefinition\\.customValidateClass').show();
		}
		else{
			$('#tr\\.editFormatDefinition\\.jrxmlPath').hide();
			$('#tr\\.editFormatDefinition\\.customValidateClass').hide();
		}
	}
	
	//-->
	</script>
</head>
<body>
<div id="mainAreaCT">
	<jsp:include page="/includes/path.jsp"/>
	<jsp:include page="/includes/subMenu.jsp"/>
	
	<div id="formatDefinitionDiv">
		<stripes:form id="qryFormatDefinitionForm" beanclass="com.feib.soeasy.action.Soez9008ActionBean" method="post"  onsubmit="javascript: return false;">
				
		<table id="queryForm">
			<tr>
				<th>業者代號<span id="mustKeyInStar">**</span></th>
				<td>
				<%if ( UserUtil.isBankGroup()){ %>				
					<div id="findGroupNoImg"><a href="javascript: void(0)" class="btnZoom">查詢</a></div>
					<stripes:text id="qryFormatDefinition.group.groupNo" name="qryFormatDefinition.group.groupNo" size="12" maxlength="12" />
				 <%} else {%>
				  <input type="text" readonly="readonly" id="qryFormatDefinition.group.groupNo" name="qryFormatDefinition.group.groupNo" value="<%out.print(UserUtil.getUserGroup().getGroupNo());%>"/>				  
				 <%}%>  
					<span id="qryFormatDefinition.group.groupName.span"><c:out value="${actionBean.qryFormatDefinition.group.groupName }"/></span>
				</td>
			</tr>
			<tr>
				<td colspan="2" class="queryFunction">
					<stripes:button id="doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
					<input type="button" id="toAddBtn" name="toAddBtn" value="新增" class="formBtn"/>
				</td>
			</tr>
		</table>
		</stripes:form>
	</div><!-- end #formatDefinitionDiv -->
	
	<!-- 業者查詢結果  -->
	<div id="queryResultDiv" style="display: none;">
	</div>
	
	
	
	<!-- 業者維護畫面  -->
	<div id="editFormatDefinitionDiv" style="display: none;"></div>
	
	
	<div id="editCommissionCodeTableDiv" style="display: none;"></div>
	
		
	<!-- Message -->
	<div id="ajaxErrorMessageDiv" style="display: none;"></div>
	
	
	
	
	
	<!-- 業者代號 查詢 -->
	<div id="findGroupDiv" style="display: none;">
		<div id="queryGroupDiv">
		<table>
			<tr>
				<th>業者代號</th>
				<td><input id="qryGroup.groupNo" type="text" size="12" maxlength="12" /> </td>
			</tr>
			<tr>
				<th>名稱</th>
				<td><input id="qryGroup.groupName" type="text" size="20" /></td>
			</tr>
			<tr>
				<td colspan="2" class="queryFunction">
					<input type="button" value="查詢" id="doAjaxQueryGroupsBtn"/>
					<input type="button" value="結束" id="doAjaxCloseGroupsBtn"/>
				</td>
			</tr>
		</table>
		</div>
		<div id="queryGroupResultDiv" style="display: none;">
		</div>
	</div>
	<div id="queryGroupHiddenFormDiv" style="display: none; ">
		<stripes:form id="queryGroupHiddenFrom" beanclass="com.feib.soeasy.action.Soez9007ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.qryGroup.groupName" name="qryGroup.groupName"/>
			<stripes:hidden id="hidden.qryGroup.groupNo" name="qryGroup.groupNo"/>
			<stripes:hidden id="hidden.queryGroupResult.pageNumber" name="queryGroupResult.pageNumber" />	
			<stripes:hidden id="hidden.queryGroupTrigger" name="queryGroupTrigger"/>
			<input type="hidden" id="method" name="doAjaxQueryGroups"/>
		</stripes:form>
	</div>
	
	<div id="queryHiddenFormDiv" style="display: none;">
		<stripes:form id="queryHiddenFrom" beanclass="com.feib.soeasy.action.Soez9008ActionBean" 
			method="post" onsubmit="javascript: waitingDialog({});">
			
			<stripes:hidden id="hidden.qryFormatDefinition.group.groupNo" name="qryFormatDefinition.group.groupNo"/>
			
			<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
			
			<stripes:hidden id="hidden.doQueryBtn" name="doQuery" class="formBtn"/>
		</stripes:form>
	</div>
	
	<div id="saveAppGroupHiddenFormDiv" style="display: none; ">
		
	</div>
	<div style="display: none; ">
	<stripes:form id="saveAppGroupHiddenFrom" beanclass="com.feib.soeasy.action.Soez9008ActionBean" 
			method="post" onsubmit="javascript: return false;">
			<stripes:hidden id="hidden.editGroup.groupPk" name="editGroup.groupPk"/>
			<stripes:hidden id="hidden.editGroup.chainstoreAmount" name="editGroup.chainstoreAmount"/>
			<stripes:hidden id="hidden.editGroup.postAmount" name="editGroup.postAmount" />	
			<stripes:hidden id="hidden.editGroup.atmAmount" name="editGroup.atmAmount"/>
			<stripes:hidden id="hidden.editGroup.remittanceAmount" name="editGroup.remittanceAmount"/>
			<stripes:hidden id="hidden.editGroup.otherAmount" name="editGroup.otherAmount"/>
			<stripes:hidden id="hidden.editGroup.bankAmount" name="editGroup.bankAmount" />
			<stripes:hidden id="hidden.editGroup.postLevel1" name="editGroup.postLevel1"/>
			<stripes:hidden id="hidden.editGroup.postLevel2" name="editGroup.postLevel2"/>
			<stripes:hidden id="hidden.editGroup.postLevel3" name="editGroup.postLevel3" />
			<stripes:hidden id="hidden.editGroup.selfAmount" name="editGroup.selfAmount" />
			<input type="hidden" id="method6" name="toSaveAppGroup"/>
		</stripes:form>
	</div>
	
</div>
</body>
</html>